﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

using Uber.Storage;

namespace Uber.HabboHotel.Advertisements
{
    class RoomAdvertisement
    {
        public uint Id;
        public string AdImage;
        public string AdLink;
        public int Views;
        public int ViewsLimit;

        public bool ExceededLimit
        {
            get
            {
                return (ViewsLimit > 0 && Views >= ViewsLimit);
            }
        }

        public RoomAdvertisement(uint mId, string mAdImage, string mAdLink, int mViews, int mViewsLimit)
        {
            this.Id = mId;
            this.AdImage = mAdImage;
            this.AdLink = mAdLink;
            this.Views = mViews;
            this.ViewsLimit = mViewsLimit;
        }

        public void OnView()
        {
            this.Views++;

            using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient())
            {
                dbClient.ExecuteQuery("UPDATE room_ads SET views = views + 1 WHERE id = '" + Id + "' LIMIT 1");
            }
        }
    }
}
